# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django import forms
from django.contrib.auth.models import AbstractUser


class Web (models.Model):
    id = models.AutoField (primary_key=True)
    title = models.CharField (max_length=150)
    body = models.TextField ()
    timestamp = models.DateTimeField ()


class WebForm (forms.ModelForm):
    """
    title = forms.CharField (max_length=150)
    body = forms.CharField (widget=forms.Textarea (attrs={'row': 3, 'cols': 60}))  # 按照页面需求写的行列大小
    timestamp = forms.DateTimeField ()
    """

    class Meta:
        model = Web
        exclude = ('timestamp',)


'''
class Meta:
    ordering = ('timestamp',)
'''


# 继承了django中的用户基本 类AbstractUser
class User (models.Model):
    id = models.AutoField (primary_key=True)
    # right_level = [(0, "普通用户"), (1, "司法鉴定员"), (2, "系统用户")]
    user_account = models.CharField (verbose_name="用户名称", unique=True, max_length=50)
    # django 要求用户名唯一
    password = models.CharField ("用户密码", max_length=128)
    created_time = models.DateTimeField ("账户创建时间", auto_now_add=True)
    email = models.EmailField ("邮箱")
    phone = models.CharField ("手机号码", unique=True, max_length=30)
    # right = models.SmallIntegerField("权限等级", choices=right_level, default=0)
    # has_confirmed = models.BooleanField(default=False)  # 确认
    credit = models.PositiveIntegerField (verbose_name="积分", default=0)
    gender = models.PositiveIntegerField (verbose_name="性别")

    # 元数据 增强可读性
    class Meta:
        verbose_name = '用户'
        ordering = ['-id']

    def __str__(self):
        return self.user_account
